<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<!DOCTYPE html>
<html lang="zh-CN">
    <head>
    <meta charset="UTF-8">
    <%@ include file="/WEB-INF/views/include/head.jsp"%> 
    <link rel="stylesheet" href="${ctxStatic}/css/list.css">
    <script type="text/javascript">
        $(function(){
            $(".tabBox ul li").each(function(){
                var index=$(this).index();

                // 量体
                var searchFitInfoListSize = $('#searchFitInfoListSize').val();

                // 试穿
                var tryOnInformationListSize = $('#tryOnInformationListSize').val();
                // 量体
                if (tryOnInformationListSize> 0) {
                	
                    $(".tabBox ul li").eq(1).addClass("active");
                    $("#fitTitle").hide();
                    // 量体隐藏
                    //$("#fit").hide();
                    $(this).addClass("active").siblings().removeClass("active");

                    $(".tabBoxSm > .tableBox").eq(index).stop(true).show().siblings().stop(true).hide();
 
                    var listH = $(':root').css('height')
                    $(window.parent.$("#mainFrame").css('height',listH));

                } else {
                    $(".tabBox ul li").eq(0).addClass("active");
                    // 试穿隐藏
                    $("#tryOnTitle").hide();
                }
                
                $(this).click(function(){

                    $(this).addClass("active").siblings().removeClass("active");

                    $(".tabBoxSm > .tableBox").eq(index).stop(true).show().siblings().stop(true).hide();
 
                    
                    
                    var listH = $(':root').css('height')
                    $(window.parent.$("#mainFrame").css('height',listH));

                })

            })

        })
        
        
        /*试穿数据恢复*/
        function reverseTryOnData() {
        	
        	// 记录值置空
        	$(".tabBoxSm > .tableBox").eq(1).find("input[name='propertyInNum']").val(null);
        	// 记录值置空
        	$(".tabBoxSm > .tableBox").eq(1).find("input[name='propertyInOut']").val(null);

        	// 参考值
			var propertyNum = $("input[name='propertyNum']");
        	
        	for(var i = 0; i < propertyNum.length; i++) {
        		// 结果值显示区
            	$('#dataShow' + i).html(propertyNum[i].value);
        	}

        }

    	// 保存方法
    	var saveForm={
            s:null,
            save:function(s){
            		// 试穿数据入力是否合法
            		
            		if (!validateTryOnFitInfo()) {
            			return;
            		}
                    this.s=s;
                    $("#inputForm").validate({
                        submitHandler : function() {
                            var params = $("#inputForm").serialize();
                            $.post("${ctx}/order/createOrder2/saveOrderToSession?id=0", params, function(result) {
                            	
                            	// 有错误
                                if (result == "false") {
                                    $("#inputForm")[0].reset();
                                }
                             	// 跳转至第二页面
                                else {
                                	window.location.href="${ctx}/order/createOrder3/form3?id=0";
                                }
                            }, 'json');
                        }
                    });
                    
            		$("#inputForm").validate({});
                    $("#inputForm").submit(); 
        	}
     	}
        
        /*试穿数据入力是否合法*/
        function validateTryOnFitInfo() {

        	// 量体属性名称
        	var propertyName = $("input[name='propertyName']");
        	// 参考值
			var propertyNum = $("input[name='propertyNum']");
        	
        	// 增值入力值
        	var propertyInNum = $("input[name='propertyInNum']");
        	// 可增加最小范围
        	var propertyInFrom = $("input[name='propertyInFrom']");
        	// 可增加最大范围
        	var propertyInTo = $("input[name='propertyInTo']");

        	// 缩减入力值
        	var propertyOutNum = $("input[name='propertyOutNum']");
        	// 可缩减最小范围
        	var propertyOutFrom = $("input[name='propertyOutFrom']");
        	// 可缩减最大范围
        	var propertyOutTo = $("input[name='propertyOutTo']");
        	
        	// 计算出的结果值
        	var resultValue = 0;
        	// 传给后台的值
        	var orderFitFitValue =  $("input[name='orderFitFitValue']");

            for (var i = 0 ; i < propertyInNum.length; i ++) {
            	// 加值，减值只能入力其中一个数据
            	if (propertyInNum[i].value != null && $.trim(propertyInNum[i].value) != "" && propertyInNum[i].value != "null" && propertyOutNum[i].value != null && $.trim(propertyOutNum[i].value) != "" && propertyOutNum[i].value != "null") {
            		// 增值，减值只能入力其中一个数据
                    layer.msg(propertyName[i].value + '<spring:message code="order_message01"/>', {time:1000});
            		// 入力焦点移至“增值入力框”
                    propertyInNum[i].focus();
            		return false;
            	}
            	
            	// 加值判断
            	if (propertyInNum[i].value != null && $.trim(propertyInNum[i].value) != "" && propertyInNum[i].value != "null"){
            		
            		// 低出增值范围！
                    if (parseFloat(propertyInNum[i].value) < parseFloat(propertyInFrom[i].value)) {
                        // 低出增值范围！
                        layer.msg(propertyName[i].value + "<spring:message code="order_message02"/>", {time:1000});
                        // 入力焦点移至“增值入力框”
                        propertyInNum[i].focus();
                        return false;
                    }
                    
                    // 超出增值范围！
            		if (parseFloat(propertyInNum[i].value) > parseFloat(propertyInTo[i].value)) {
            			// 超出增值范围！
                        layer.msg(propertyName[i].value + "<spring:message code="order_message03"/>", {time:1000});
                        // 入力焦点移至“增值入力框”
                        propertyInNum[i].focus();
                        return false;
            		}
            	}
            	
            	// 减值判断
                // 加值判断
                if (propertyOutNum[i].value != null && $.trim(propertyOutNum[i].value) != "" && propertyOutNum[i].value != "null"){
                	
                	// 低出减值范围！
                    if (parseFloat(propertyOutNum[i].value) < parseFloat(propertyOutFrom[i].value)) {
                        // 低出减值范围！
                        layer.msg(propertyName[i].value + "<spring:message code="order_message04"/>", {time:1000});
                        // 入力焦点移至“减值入力框”
                        propertyOutNum[i].focus();
                        return false;
                    }
                    
                    // 超出减值范围！
                    if (parseFloat(propertyOutNum[i].value) > parseFloat(propertyOutTo[i].value)) {
                        // 超出减值范围！
                        layer.msg(propertyName[i].value + "<spring:message code="order_message05"/>", {time:1000});
                        // 入力焦点移至“减值入力框”
                        propertyOutNum[i].focus();
                        return false;
                    }
                }
            	
            	// 入力正常则改变相应的值
            	// 加值
            	if (propertyInNum[i].value != null && $.trim(propertyInNum[i].value) != "" && propertyInNum[i].value != "null") {
            		
                	// 计算出的结果值
                	resultValue = parseFloat(propertyNum[i].value) + parseFloat(propertyInNum[i].value);
                	// 结果值显示区
                	$('#dataShow' + i).html(resultValue);
                	// 传值给后台
                	$('#orderFitFitValue' + i).val(resultValue);
            	}
            	
            	// 减值
            	if (propertyOutNum[i].value != null && $.trim(propertyOutNum[i].value) != "" && propertyOutNum[i].value != "null") {
            		
                	// 计算出的结果值
                	resultValue = parseFloat(propertyNum[i].value) - parseFloat(propertyOutNum[i].value);
                	// 结果值显示区
                	$('#dataShow' + i).html(resultValue);
                	// 传值给后台
                	$('#orderFitFitValue' + i).val(resultValue);
            	}
            }
            
            return true;
        }
        
    </script>
</head>
<body>
<div class="myshop">
        <!-- 创建订单 -->
        <p class="myshoptop"><spring:message code="order_create_order"/></p>
</div>

<div class="myshop_middle_order">

		<!-- 标题 -->
		<div class="orderTit orderTitShow clearfix">
			<div class="titSm off">
                <!-- 基本信息 -->
                <p><spring:message code="order_basic_info"/></p>
				<img src="${ctxStatic}/images/order_01_off.png">
			</div>
			<div class="titSm off" onclick='window.location.href="${ctx}/order/createOrder2/initUpdateOrder2?id=${order.id}"'>
                <!-- 量体信息 -->
                <p><spring:message code="order_fit_property_info"/></p>
				<img src="${ctxStatic}/images/order_02_off.png">
			</div>
			<div class="titSm off" onclick='window.location.href="${ctx}/order/createOrder3/form3?id=${order.id}"'>
                <!-- 款式定制 -->
                <p><spring:message code="order_style_customization"/></p>
				<img src="${ctxStatic}/images/order_03_on.png">
			</div>
			<div class="titSm off" onclick='window.location.href="${ctx}/order/createOrder3/form4?id=${order.id}"'>
                <!-- 辅料 -->
                <p><spring:message code="order_accessory"/></p>
				<img src="${ctxStatic}/images/order_04_on.png">
			</div>
			<div class="titSm off" onclick='window.location.href="${ctx}/order/createOrder3/form5?id=${order.id}"'>
                <!-- 配料 -->
                <p><spring:message code="order_burdening"/></p>
				<img src="${ctxStatic}/images/order_05_on.png">
			</div>
			<div class="titSm off" onclick='window.location.href="${ctx}/order/createOrder3/form6?id=${order.id}"'>
                <!-- 刺绣 -->
                <p><spring:message code="order_embroidery"/></p>
				<img src="${ctxStatic}/images/order_06_on.png">
			</div>
			<div class="titSm off" onclick='window.location.href="${ctx}/order/createOrder3/form7?id=${order.id}"'>
                <!-- 标牌 -->
                <p><spring:message code="order_brand"/></p>
				<img src="${ctxStatic}/images/order_07_on.png">
			</div>
			<div class="titSm off" onclick='window.location.href="${ctx}/order/createOrder3/form8?id=${order.id}"'>
                <!-- 售价 -->
                <p><spring:message code="order_sales_price"/></p>
				<img src="${ctxStatic}/images/order_08_on.png">
			</div>
		</div>
		<div class="clearfix">
		<div class="contentBox cnBx">
        <!-- 量体信息 -->
        <p class="contentTit"><spring:message code="order_fit_property_info"/></p>
        <div class="tabBox orderTab">
            <ul class="clearfix">
             <li class="active" id="fitTitle"><spring:message code="order_fit_property_data"/></li>
              <!-- 试穿数据 -->
             <li id="tryOnTitle"><spring:message code="order_wear_data"/></li>
                
            </ul>
        </div>
        <form id="inputForm">
       		<div class="tabBoxSm" id="fit">
                    <!-- 量体数据 -->
                    <!-- 隐藏数据 -->
                    <!-- 净量体个数 -->
                    <input id="searchFitInfoListSize" type="hidden" value="${searchFitInfoList.size()}">
                    <!--试穿数据个数-->
                    <input id="tryOnInformationListSize" type="hidden" value="${tryOnInformationList.size()}">
                    <!-- id -->
                    <input id="orderId" value="${order.id}" type="hidden">
                    
                    <div class="tableBox formBox2 scrollBox" style="width:100%;padding:10px;">
                        <c:forEach items="${searchFitInfoList}" var="fitItem" varStatus="fitStatus">
                            <c:if test="${fitStatus.index%4 == 0}">
                                <div class="data clearfix">
                            </c:if>
                                <!-- 左两列 -->
                                <c:if test="${fitStatus.index%4 == 0}">
                                    <div class="w-400 fl clearfix">
                                </c:if>
                                     <c:if test="${fitStatus.index%4 == 0}">
                                        <div class="w-190 fl clearfix">
                                            <div class="data_id">${fitItem.propertyNameCn}</div>
                                                <input name="orderFitItemValue" type="hidden" value="${fitItem.propertyValue}">
                                                <input name="orderFitItemCD" type="hidden" value="${fitItem.propertyCd}">
                                                <input name="orderFitFitValue" onfocus="unFormat(this)" maxlength="4" class="form-controlSm" value="${fitItem.fitValue}"
                                                    data-rule-required="true" data-msg-required="<spring:message code="order_please_input_all_value"/>"
                                                    data-rule-number="true" data-msg-number="<spring:message code="order_please_input_valid_value"/>"
                                                > ${fns:getDictName(fitItem.propertyUnitCd)}
                                            </div>
                                    </c:if>
                                    <c:if test="${fitStatus.index%4 == 1}">
                                       <div class="w-190 fr clearfix">
                                            <div class="data_id">${fitItem.propertyNameCn}</div>
                                                <input name="orderFitItemValue" type="hidden" value="${fitItem.propertyValue}">
                                                <input name="orderFitItemCD" type="hidden" value="${fitItem.propertyCd}">
                                                <input name="orderFitFitValue" onfocus="unFormat(this)" maxlength="4"  class="form-controlSm" value="${fitItem.fitValue}"
                                                    data-rule-required="true" data-msg-required="<spring:message code="order_please_input_all_value"/>"
                                                    data-rule-number="true" data-msg-number="<spring:message code="order_please_input_valid_value"/>"
                                                >${fns:getDictName(fitItem.propertyUnitCd)}
                                        </div>
                                    </c:if>
                                <c:if test="${fitStatus.index%4 == 1}">
                                    </div>
                                </c:if>
                                <!-- 右两列 -->
                                <c:if test="${fitStatus.index%4 == 2}">
                                    <div class="w-400 fr clearfix">
                                </c:if>
                                    <c:if test="${fitStatus.index%4 == 2}">
                                        <div class="w-190 fl clearfix">
                                        	<div class="data_id">${fitItem.propertyNameCn}</div>
                                                <input name="orderFitItemValue" type="hidden" value="${fitItem.propertyValue}">
                                                <input name="orderFitItemCD" type="hidden" value="${fitItem.propertyCd}">
                                                <input name="orderFitFitValue"  class="form-controlSm" value="${fitItem.fitValue}"
                                                 data-rule-required="true" data-msg-required="<spring:message code="order_please_input_all_value"/>"
                                                 data-rule-number="true" data-msg-number="<spring:message code="order_please_input_valid_value"/>"> ${fns:getDictName(fitItem.propertyUnitCd)}
                                        	</div>
                                    </c:if>
                                        <c:if test="${fitStatus.index%4 == 3}">
                                            <div class="w-190 fr clearfix">
                                                <div class="data_id">${fitItem.propertyNameCn}</div>
                                                <input name="orderFitItemValue" type="hidden" value="${fitItem.propertyValue}">
                                                <input name="orderFitItemCD" type="hidden" value="${fitItem.propertyCd}">
                                                <input  name="orderFitFitValue" onfocus="unFormat(this)" maxlength="4" class="form-controlSm" value="${fitItem.fitValue}"
                                                data-rule-required="true" data-msg-required="<spring:message code="order_please_input_all_value"/>"
                                                data-rule-number="true" data-msg-number="<spring:message code="order_please_input_valid_value"/>"
                                                > ${fns:getDictName(fitItem.propertyUnitCd)}
                                            </div>
                                        </c:if>
                                         <c:if test="${fitStatus.index%4 == 3 || fitStatus.index == (fn:length(searchFitInfoList) - 1)}">
                                           </div>
                                        </c:if>
                            <c:if test="${fitStatus.index%4 == 3 || fitStatus.index == (fn:length(searchFitInfoList) - 1)}">
                                </div>
                            </c:if>
                        </c:forEach>
                         </form>
                    </div>

            
            <!-- 试穿数据 -->
            <div class="tableBox formBox2 scrollBox none" id="tryOnDiv">
                <form id="inputForm2">
                 <c:set var="myIndex" scope="page" value="0"></c:set>
                <div class="clearfix">
                    <!-- 外循环体：试穿数据类型-->
                    <c:forEach items="${tryOnInformationList}" var="fitCategoryItem" varStatus="fitCategoryStatus">
                        <div class="">
                            <!-- 试穿数据类型名称 -->
                            <p class="order2-tit">${fitCategoryItem.fitCategoryName}</p>
                             <!-- 内循环体：试穿类型数据下的具体数据  -->
                             <c:forEach items="${fitCategoryItem.fitInfoList}" var="fitInfoItem" varStatus="fitInfoStatus">
                                <c:if test="${fitInfoStatus.index%2 == 1}">
                                    <!-- 折行 -->
                                    <div class="clearfix">
                                </c:if>
                                        <div class="order-2-Sm clearfix">
                                        	<!-- 隐藏变量 -->
                                        	<input name="orderFitItemCD"    type="hidden"  value="${fitInfoItem.propertyCd}">
                                        	<input name="orderFitItemValue" type="hidden"  value="${fitInfoItem.propertyValue}">
                                        	<input name="orderFitFitValue"  type="hidden"  id="orderFitFitValue${myIndex}">
                                            <!-- 量体名称 -->
                                            <p class="data_id">${fitInfoItem.propertyNameCn}<input name="propertyName" type="hidden" value="${fitInfoItem.propertyName}"/></p>
                                            <!-- 量体参考值 -->
                                            <p class="order2-txt"><label id="dataShow${myIndex}">${fitInfoItem.actualNum}</label><input name="propertyNum" type="hidden" value="${fitInfoItem.propertyNum}"/></p>
                                            <!-- 可增加范围 -->
                                            <p class="order2-20">+</p>
                                            <input class="form-control order2-inp" name="propertyInNum" value="${fitInfoItem.addNum}" onfocus="unFormat(this)" maxlength="4" data-rule-number="true" data-msg-required="请输入合法数值!" onblur="validateTryOnFitInfo()">
                                            <input name="propertyInFrom" type="hidden" value="${fitInfoItem.propertyInFrom}"/>
                                            <input name="propertyInTo" type="hidden" value="${fitInfoItem.propertyInTo}"/>
                                            <p class="order2-int"> (${fitInfoItem.propertyInFrom}~${fitInfoItem.propertyInTo})</p>
                                            <!-- 可缩减范围 -->
                                            <p class="order2-20">-</p>
                                            <input class="form-control order2-inp" name="propertyOutNum" value="${fitInfoItem.minusNum}" onfocus="unFormat(this)" maxlength="4"  data-rule-number="true" data-msg-required="请输入合法数值!" onblur="validateTryOnFitInfo()">
                                            <input name="propertyOutFrom" type="hidden" value="${fitInfoItem.propertyOutFrom}"/>
                                            <input name="propertyOutTo" type="hidden" value="${fitInfoItem.propertyOutTo}"/>
                                            <p class="order2-int">(${fitInfoItem.propertyOutFrom}~${fitInfoItem.propertyOutTo})</p>
                                        </div>
                                        
                                <c:if test="${fitInfoStatus.index%2 == 1 || fitInfoStatus.index == (fn:length(fitCategoryItem.fitInfoList) - 1)}">
                                   </div>
                                </c:if>
                                   <c:set var="myIndex" scope="page" value="${myIndex + 1}"></c:set>
                             </c:forEach>
                        </div>
                    </c:forEach>
                </div>
               </form>
            </div>
            
            </div>
        </div>
        <!-- 订单信息显示 -->
        <%@ include file="/WEB-INF/views/modules/order/orderCreateTitle.jsp"%>
    </div>
    <div class="Pre-box">
        <!-- 下一步 -->
        <div class="Pre-1" onclick="saveForm.save(0);"><spring:message code="order_next_step"/></div>
        <!-- 取消 -->
        <div class="Pre-2" onclick="window.parent.frames[0].location.href = '${ctx}/order/order/'"><spring:message code="order_cancel"/></div>
    </div>
</div>

<script>
    var windowH2 = window.parent.windowHIframe
    $('.scrollBox').css('height', windowH2 - 420);
    $('.TxtInfoSm1').css('height', windowH2 - 368);

    var listH = $(':root').css('height')
    $(window.parent.$("#mainFrame").css('height',listH));
</script>
</body>
</html>